
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <!-- 标题 -->
    <title>设置打印机</title>
    <!-- 关键词 -->
    <meta name="keywords" content="" />
    <!-- 网站简介 -->
    <meta name="description" content="" />
    <!-- 自适应屏幕 -->
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <!-- IE兼容 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 最新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="Content/bootstrap.min.css">
    <!-- 核心 CSS 文件 -->
    <link rel="stylesheet" href="Content/style.css" type="text/css">

    <script src="scripts/jquery-1.9.1.min.js"></script>
    <script src="scripts/bootstrap.min.js"></script>
    <script src="scripts/Dialog.js"></script>
    <link rel="stylesheet" href="Content/weui.css" />
    <script src="scripts/LodopFuncs.js"></script>

</head>
<body>
    <div class="index">
        <div class="index-top">
            外婆家1号
        </div>
        <div class="index-center">
            <div class="row">
                <div class="col-sm-2">
                    <div class="index-nav">
                            <p class="lastuser">还没有员工操作过</p>
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="index-nav nav-home">
                        <a href="/System/RestIndex" class="active">首页</a>
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="index-nav nav-home">
                        <a href="/System/SetPrint">设置打印机</a>
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="index-nav nav-home">
                        <a href="/System/ResetPwd">修改密码</a>
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="index-nav nav-home nav-pad">
                        
                        <a href="/System/SelPad"><span>2</span>切换PAD</a>
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="index-nav nav-home">
                        <a href="/">退出登录</a>
                    </div>
                </div>
            </div>
        </div>
        </div>


    <div class="container">
        <div class="row">
            <div class="col-sm-12 text-center">
                <b>打印机列表</b>
            </div>            
        </div>
        <div id="printlist"><div class="row"><div class="col-sm-1 text-right"><b>1</b></div> <div class="col-sm-8 printname text-left">PageManager PDF Writer</div><div class="col-sm-1 text-right"><select><option value="" selected="">请选择</option><option value="1">厨房</option><option value="0">前台</option><option value="2">公用</option></select></div></div> <div class="row"><div class="col-sm-1 text-right"><b>2</b></div> <div class="col-sm-8 printname text-left">Microsoft XPS Document Writer</div><div class="col-sm-1 text-right"><select><option value="" selected="">请选择</option><option value="1">厨房</option><option value="0">前台</option><option value="2">公用</option></select></div></div> <div class="row"><div class="col-sm-1 text-right"><b>3</b></div> <div class="col-sm-8 printname text-left">Microsoft Print to PDF</div><div class="col-sm-1 text-right"><select><option value="" selected="">请选择</option><option value="1">厨房</option><option value="0">前台</option><option value="2">公用</option></select></div></div> <div class="row"><div class="col-sm-1 text-right"><b>4</b></div> <div class="col-sm-8 printname text-left">FX DocuPrint M268 dw Printer</div><div class="col-sm-1 text-right"><select><option value="" selected="">请选择</option><option value="1">厨房</option><option value="0">前台</option><option value="2">公用</option></select></div></div> <div class="row"><div class="col-sm-1 text-right"><b>5</b></div> <div class="col-sm-8 printname text-left">Fax</div><div class="col-sm-1 text-right"><select><option value="" selected="">请选择</option><option value="1">厨房</option><option value="0">前台</option><option value="2">公用</option></select></div></div> </div>
        <div class="row">
            <div class="col-sm-12 text-center">
                <a href="#" class="weui_btn weui_btn_mini weui_btn_primary" onclick="setprint()">设置</a>
                <a href="#" class="weui_btn weui_btn_mini weui_btn_primary" onclick="printtest()">测试</a>
            </div>
        </div>
        <div id="currentprintlist" style="display:none;">
              <div title="1">GP-5890X Series</div>
              <div title="0">GP-5890 Series</div>
        </div>
    </div>

    <script language="javascript" type="text/javascript">   
        var LODOP = getLodop();
        function list() {
            var s = "";
            for (var i = 0; i < getPrinterCount() ; i++) {
                s += '<div class="row"><div class="col-sm-1 text-right"><b>' + (i + 1) + '</b></div> ';
                var pr = getPrinterName(i);
                s += '<div class="col-sm-8 printname text-left">'+pr+'</div>';
                s += '<div class="col-sm-1 text-right"><select>';
                var rev = getprintsta(pr);
                if (rev == '') {
                    s += '<option value="" selected>请选择</option>';
                }
                else {
                    s += '<option value="">请选择</option>';
                }

                if (rev == '1') {
                    s += '<option value="1" selected>厨房</option>';
                }
                else {
                    s += '<option value="1">厨房</option>';
                }

                if (rev == '0') {
                    s += '<option value="0" selected>前台</option>';
                }
                else {
                    s += '<option value="0">前台</option>';
                }

                if (rev == '2') {
                    s += '<option value="2" selected>公用</option>';
                }
                else {
                    s += '<option value="2">公用</option>';
                }
                
                s += '</select></div></div> ';
            }

            $("#printlist").html(s);
        }

        function getprintsta(printname)
        {
            var rev = "";
            $("div#currentprintlist div").each(function (index) {
                var s = $(this).html();
                if (s == printname)
                {
                    rev = $(this).attr("title");
                    if (rev != "0" && rev != "1") rev = "2";
                    return false;
                }
            })            

            return rev;
        }

        function getPrinterCount() {
            return LODOP.GET_PRINTER_COUNT();
        };
        function getPrinterName(iPrinterNO) {
            return LODOP.GET_PRINTER_NAME(iPrinterNO);
        };

        list();



        function setprint() {
            var formParam = GetParam();
            $.ajax({
                type: 'post',
                url: '/System/SetSystemPrint',
                data: formParam,
                cache: false,
                dataType: 'json',
                success: function (data) {
                    if (data.success == true) {
                        WinAlert("设置成功");
                    }
                    else {
                        WinAlert(data.message);
                    }
                },
                error: function () {
                    WinAlert("系统异常");
                }
            });
        }

        function GetParam() {
            var obj = {};

            var i = 0;
            $("div#printlist .row").each(function (index) {
                var o = $(this).find(".printname");
                var o1 = $(this).find("select").val();
                if (o1 == "")
                {
                    return true;
                }

                obj["model.list[" + i + "].print_name"] = $(o).html();
                obj["model.list[" + i + "].cookroom"] = o1;
                i++;
            })


            return obj;

        }




        ///构造html
        ///type  1:厨房   0：前台
        function CreatePrintHtml(type) {
            LODOP.PRINT_INIT("s");
            LODOP.SET_PRINT_PAGESIZE(3, 580, 40, "");
            var s = "厨房测试";
            if (type == 0) s = "前台测试";
            if (type == 2) s = "前台和厨房测试";
            LODOP.ADD_PRINT_HTM(5, 5, "100%", "100%", s);
            LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
            LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
        }

        ///打印前台
        function printtest() {
            $("div#printlist .row").each(function (index) {
                var o = $(this).find(".printname");
                var o1 = $(this).find("select").val();
                if (o1 == "") {
                    return true;
                }

                CreatePrintHtml(o1);
                if (LODOP.SET_PRINTER_INDEXA($(o).html()))
                    //LODOP.PREVIEW();
                LODOP.PRINT();
            })
        }
    </script>

</body>
</html>
